using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Entity;
using DataAccess;

namespace Business
{
    public class UsersBusiness
    {
        public DataTable GetUsers()
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Users";
            dt = DA.GetDataTable(sql);
            return dt;
        }

        public int AddUser(UsersEntity users)
        {
            int i = 0;
            string sql = "INSERT into [dbo].[Users] VALUES (@UserName, @Password, @Role)";
            string[] paras = { "@UserName", "@Password", "@Role" };
            object[] values = { users.UserName, users.Password, users.Role };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public int UpdateUser(UsersEntity users)
        {
            int i = 0;
            string sql = "UPDATE [dbo].[Users] SET UserName = @UserName, Password = @Password, Role = @Role WHERE UserID = @UserID";
            string[] paras = { "@UserName", "@Password", "@Role", "@UserID" };
            object[] values = { users.UserName, users.Password, users.Role, users.UserID };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public int DeleteUser(int UserID)
        {
            int i = 0;
            string sql = "DELETE FROM [dbo].[Users] WHERE UserID = @UserID";
            string[] paras = { "@UserID" };
            object[] values = { UserID };
            i = DA.ExecuteNonQuery(sql, commandType.Text, parameters, values);
            return i;
        }

        public DataTable GetUser(int UserID)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Users WHERE UserID = @UserID";
            string[] paras = { "@UserID" };
            object[] values = { UserID };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }

        public DataTable GetUser(string UserName)
        {
            DataTable dt = new DataTable();
            string sql = "SELECT * FROM Users WHERE UserName = @UserName";
            string[] paras = { "@UserName" };
            object[] values = { UserName };
            dt = DA.GetDataTable(sql, commandType.Text, parameters, values);
            return dt;
        }
    }
}
